package com.example.lib_audio.tools

import android.animation.ObjectAnimator
import android.animation.ValueAnimator
import android.util.Log
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import com.example.lib_audio.audio.AudioPlayer
import com.example.lib_audio.eventbus.AudioChangeProgressEvent
import org.greenrobot.eventbus.EventBus

class AudioAnimTool(val target:ImageView) {
    private var anim:ObjectAnimator? = null

    //旋转动画
    fun rotateAnim(start:Float, end:Float){
        anim = ObjectAnimator.ofFloat(target,"rotation",start,end).apply {
            duration = 5000
            repeatMode = ValueAnimator.RESTART
            repeatCount = ValueAnimator.INFINITE //无限
            interpolator = LinearInterpolator()  //匀速

            start()
        }
    }

    fun start(start:Float, end:Float){
        if(anim != null){
            anim!!.cancel()
        }
        rotateAnim(start, end)
    }

    fun pause(){
        anim?.pause()
    }

    fun resume(){
        anim?.resume()
    }

    fun stop(){
        anim?.cancel()
    }
}